package shapewar.engine.model.abst;

import shapewar.engine.calc.Calcer;
import shapewar.engine.calc.Pos;
import shapewar.engine.intefac.IHittable;
import shapewar.engine.intefac.IMovable;
import shapewar.engine.intefac.IRepeat;
import shapewar.engine.presenter.EngineContext;
import shapewar.engine.presenter.EngineThread;
import shapewar.engine.presenter.Presenter;

public class ModelAdapter extends Model implements IRepeat,IHittable,IMovable{
	private EngineThread et;
	protected Pos pos;
	protected Presenter pst;
	protected Calcer calcer;
	protected Pos target;
	protected EngineContext ect;
	protected float speed;
	
	public ModelAdapter(Presenter pst,int id, float x, float y, float r, int depth) {
		super(id, x, y, r, depth);
		this.pos = new Pos(x,y);
		this.target = new Pos(x,y);
		this.pst = pst;
		this.ect = pst.ect;
		this.calcer = pst.calcer;
	}
	
	public ModelAdapter(Presenter pst,int id, float x, float y, float[][] v, int depth) {
		super(id, x, y, v, depth);
		this.pos = new Pos(x,y);
		this.target = new Pos(x,y);
		this.pst = pst;
		this.ect = pst.ect;
		this.calcer = pst.calcer;
	}
	
	@Override
	public void die() {
		
	}
	
	@Override
	public void repeat() {
		
	}
	
	@Override
	public void setTargetPos(Pos pos){
		this.target = pos;
		_rotation = calcer.calcAngle(getPos(), pos);
	}
	
	@Override
	public Pos getTargetPos() {
		return target;
	}
	
	@Override
	public float getSpeed() {
		return speed;
	}
	
	@Override
	public void moveTo(Pos pos) {
		setTargetPos(pos);
	}
	
	@Override
	public ModelAdapter getFather() {
		return this;
	}
	
	@Override
	public void setThread(EngineThread et) {
		this.et = et;
	}

	@Override
	public EngineThread getEngineThread() {
		return et;
	}

	public void setPos(Pos pos) {
		_x = pos.x;
		_y = pos.y;
		this.pos = pos;
		pst.bridge.invalidate(this);
	}

	public Pos getPos() {
		pos.x = _x;
		pos.y = _y;
		return pos;
	}
	
	@Override
	public float[][] getVertices() {
		return v;
	}
	
	@Override
	public float getHitableDistance() {
		return r;
	}

	@Override
	public void init() {
		
	}

	@Override
	public void destory() {
		
	}
	
}
